<html>
<head><meta charset="utf-8"><title>match on Option&lt;String&gt; · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html">match on Option&lt;String&gt;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="148321495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321495">(Nov 25 2018 at 14:59)</a>:</h4>
<p>Is there a good way to match on an <code>Option&lt;String&gt;</code>, with string literals?</p>



<a name="148321497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321497">(Nov 25 2018 at 14:59)</a>:</h4>
<p>for <code>String</code> there is <code>as_ref</code>, but that does not work here</p>



<a name="148321549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321549">(Nov 25 2018 at 15:00)</a>:</h4>
<p>ah, <code>.as_ref().map(|s| &amp;**s)</code> works</p>



<a name="148321550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321550">(Nov 25 2018 at 15:00)</a>:</h4>
<p>yeah tho that is exceedingly fugly</p>



<a name="148321558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321558">(Nov 25 2018 at 15:01)</a>:</h4>
<p>yeah</p>



<a name="148321560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321560">(Nov 25 2018 at 15:01)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span>  try <code>.deref()</code> ?</p>



<a name="148321605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321605">(Nov 25 2018 at 15:02)</a>:</h4>
<p>but thats not implemented for <code>Option</code>?</p>



<a name="148321607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321607">(Nov 25 2018 at 15:02)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span>  <a href="https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.deref" target="_blank" title="https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.deref">https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.deref</a></p>



<a name="148321659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321659">(Nov 25 2018 at 15:04)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@Mazdak Farrokhzad</span> ah! thanks. I had no idea.</p>



<a name="148321660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321660">(Nov 25 2018 at 15:04)</a>:</h4>
<p>the name is odd though</p>



<a name="148321663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321663">(Nov 25 2018 at 15:05)</a>:</h4>
<p>I am taking a reference, not dereferencing one</p>



<a name="148321676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321676">(Nov 25 2018 at 15:05)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span>  hehe kinda; it's a bit hacky and recent</p>



<a name="148321678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321678">(Nov 25 2018 at 15:05)</a>:</h4>
<p>but nice</p>



<a name="148321722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321722">(Nov 25 2018 at 15:06)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> maybe it should be called <code>.map_ref()</code> ?</p>



<a name="148321735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321735">(Nov 25 2018 at 15:07)</a>:</h4>
<p>ostensibly it is consistent with the <code>.as_ref()</code> method on Option tho</p>



<a name="148321737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321737">(Nov 25 2018 at 15:07)</a>:</h4>
<p>as ref always returns an optional ref, that makes sense</p>



<a name="148321743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321743">(Nov 25 2018 at 15:07)</a>:</h4>
<p>ye</p>



<a name="148321794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321794">(Nov 25 2018 at 15:09)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> that method does exactly what <code>Deref::deref</code> does.</p>



<a name="148321798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321798">(Nov 25 2018 at 15:10)</a>:</h4>
<p>within an option, that is.</p>



<a name="148321839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321839">(Nov 25 2018 at 15:10)</a>:</h4>
<p>(<code>&lt;String as Deref&gt;::deref(x: &amp;String) -&gt; &amp;str</code>)</p>



<a name="148321849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321849">(Nov 25 2018 at 15:11)</a>:</h4>
<p>it's <code>fmap deref</code> sorta :P</p>



<a name="148321850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148321850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148321850">(Nov 25 2018 at 15:11)</a>:</h4>
<blockquote>
<p>it's <code>fmap deref</code> sorta :P</p>
</blockquote>
<p>plus auto-ref^^</p>



<a name="148327276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148327276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148327276">(Nov 25 2018 at 18:19)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@Mazdak Farrokhzad</span> ohai.</p>



<a name="148327277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148327277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148327277">(Nov 25 2018 at 18:19)</a>:</h4>
<p>welcome to Zulip.</p>



<a name="148327992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148327992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148327992">(Nov 25 2018 at 18:44)</a>:</h4>
<p>ohai!</p>



<a name="148340366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148340366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148340366">(Nov 26 2018 at 01:29)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> something like generalized ref/box patterns would help</p>



<a name="148340371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148340371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148340371">(Nov 26 2018 at 01:29)</a>:</h4>
<p>i.e., <code>match opt_string { Some(&amp;"Hello!") =&gt; ..., None =&gt; ... }</code></p>



<a name="148360656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148360656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148360656">(Nov 26 2018 at 11:07)</a>:</h4>
<p>yeah... though the syntax looks a bit odd here, usually pattern syntax matches construction syntax, but <code>Some(&amp;"hello")</code> is not how you construct an <code>Option&lt;String&gt;</code></p>



<a name="148360660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148360660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148360660">(Nov 26 2018 at 11:07)</a>:</h4>
<p><code>Some(box "hello")</code> would make a bit more sense</p>



<a name="148387547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148387547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148387547">(Nov 26 2018 at 18:38)</a>:</h4>
<p><code>Some (box "hello")</code> would imply ownership, i.e., <code>DerefOwn</code></p>



<a name="148387558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148387558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148387558">(Nov 26 2018 at 18:38)</a>:</h4>
<p>you probably want <code>Deref</code></p>



<a name="148387787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148387787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148387787">(Nov 26 2018 at 18:41)</a>:</h4>
<p>In analogy with <code>box</code> <em>expressions</em> constructing arbitrary smart pointers (e.g. Rc) I would intuitively prefer if this syntax simply "matches on the pointee" and if the nested pattern moves out then that is only valid if you can move out of that smart pointer type. It's true that <code>box</code> isn't a great keyword for that because of the similarity with <code>Box</code>, but the same issue applies to <code>box EXPR</code> so it's not pattern-specific.</p>



<a name="148387895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148387895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148387895">(Nov 26 2018 at 18:43)</a>:</h4>
<p>oh, ugh, <code>box</code>-for-non-<code>Box</code> was never implemented</p>



<a name="148387915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148387915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148387915">(Nov 26 2018 at 18:43)</a>:</h4>
<p>I would prefer something like <code>&amp;&lt;pat&gt;</code> does a <code>Deref</code>, <code>&amp;mut &lt;pat&gt;</code> does a <code>DerefMut</code>, and <code>box &lt;pat&gt;</code> does a <code>DerefOwn</code>.</p>



<a name="148399151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148399151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148399151">(Nov 26 2018 at 21:22)</a>:</h4>
<blockquote>
<p><code>Some (box "hello")</code> would imply ownership, i.e., <code>DerefOwn</code></p>
</blockquote>
<p>well, I am matching a <code>String</code> which is owned like a <code>box</code></p>



<a name="148399722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148399722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148399722">(Nov 26 2018 at 21:32)</a>:</h4>
<p>right, but I would expect that to move _out_ of the string.</p>



<a name="148399955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148399955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148399955">(Nov 26 2018 at 21:36)</a>:</h4>
<p>why? even if you view box patterns as solely about DerefOwned, afaik every other pattern that can move out doesn't <em>have to</em>, e.g. <code>Some(_)</code> doesn't move out of an Option while <code>Some(x)</code> does (default binding modes nonwithstanding)</p>



<a name="148399966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148399966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148399966">(Nov 26 2018 at 21:37)</a>:</h4>
<p>or is this because to match you first have to call DerefOwned and then you can't put it back?</p>



<a name="148399975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148399975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148399975">(Nov 26 2018 at 21:37)</a>:</h4>
<p>the latter</p>



<a name="148399987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148399987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148399987">(Nov 26 2018 at 21:37)</a>:</h4>
<p>and also, there are types which you want to match on as a reference which do not own their contents.</p>



<a name="148400722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148400722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148400722">(Nov 26 2018 at 21:49)</a>:</h4>
<p>the thing is, <code>"hello"</code> already is a reference</p>



<a name="148400766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148400766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148400766">(Nov 26 2018 at 21:50)</a>:</h4>
<p><code>&amp;"hello"</code> should match an <code>&amp;&amp;str</code>...</p>



<a name="148412634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148412634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148412634">(Nov 27 2018 at 01:45)</a>:</h4>
<p>Yes, and?</p>



<a name="148412635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148412635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148412635">(Nov 27 2018 at 01:45)</a>:</h4>
<p>generalized reference patterns :P</p>



<a name="148628840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/match%20on%20Option%3CString%3E/near/148628840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/match.20on.20Option.3CString.3E.html#148628840">(Nov 27 2018 at 10:10)</a>:</h4>
<p>generalize all the things :P</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>